package com.emily.test.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.emily.test.constant.ReturnValueConstants;
import com.emily.test.controller.result.ResponseResult;
import com.emily.test.model.SSalary;
import com.emily.test.service.RedisService;
import com.emily.test.service.SalaryService;
import com.emily.test.utils.ConstentUtil;
import com.emily.test.utils.DateUtil;
import com.emily.test.utils.ExcelData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author tqx
 * @company haihui
 * @create 2019-04-25 13:46
 */
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping(value = "salaryController")
@Api(value = "SalaryControllerApi", description = "SalaryController接口类", position = 1, produces = MediaType.APPLICATION_JSON_VALUE)
public class SalaryController {
    private Logger logger = LoggerFactory.getLogger(SalaryController.class);

    @Autowired
    private SalaryService salaryService;

    @Autowired
    private RedisService redisService;

    /**
     * 解析excel文件
     * @param file excel文件
     * @return
     */
    @ApiOperation(value = "薪资信息导入接口", notes = "薪资信息导入接口")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "salaryArray", value = "薪水信息数组", required = true),
////            @ApiImplicitParam(name = "jiaBanGongZuoRi", value = "加班工作日(时)"),
////            @ApiImplicitParam(name = "jiaBanZhouMo", value = "加班周末（时）"),
////            @ApiImplicitParam(name = "jiaBanFaJia", value = "法定节日加班（时）"),
//            @ApiImplicitParam(name = "salaryTime", value = "工资时间", required = true)
    })
    @PostMapping(value = "parseExcelInfo")
    public  ResponseResult parseExcelInfo(MultipartFile file) {
        try {
            List<String[]> excelData = ExcelData.getExcelData(file);
            logger.info("获取excel文件信息成功:{}",excelData);
            return  ResponseResult.success(ReturnValueConstants.PARSE_SUCCESS,excelData);
        } catch (IOException e) {
            logger.error("获取excel文件信息异常!");
            e.printStackTrace();
            return ResponseResult.fail(ReturnValueConstants.PARSE_FAILURE);
        }
    }

    /**
     * 薪资json数组导入到数据库
     * @param jsonObject 薪资json数组
     * @return
     */
    @ApiOperation(value = "薪资信息导入接口", notes = "薪资信息导入接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "salaryArray", value = "薪水信息数组", required = true),
//            @ApiImplicitParam(name = "jiaBanGongZuoRi", value = "加班工作日(时)"),
//            @ApiImplicitParam(name = "jiaBanZhouMo", value = "加班周末（时）"),
//            @ApiImplicitParam(name = "jiaBanFaJia", value = "法定节日加班（时）"),
            @ApiImplicitParam(name = "salaryTime", value = "工资时间", required = true)
    })
    @PostMapping(value = "salaryInfo")
    public ResponseResult salaryInfo(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
        String token = request.getHeader("token");
        System.out.println("token===="+token);
        Map<String,Object> userMap=  (Map<String,Object>)redisService.get(token);
        String  companyCode = (String) userMap.get("companyCode");
//        String  companyCode = "SDHH";
        JSONArray salaryArray = jsonObject.getJSONArray("salaryArray");
        if(ConstentUtil.isEmpty(salaryArray)){
            return ResponseResult.fail("薪资信息为空，请查验");
        }
        String salaryTime =jsonObject.getString("salaryTime");
        if(ConstentUtil.isEmpty(salaryTime)){
            return ResponseResult.fail("请选择时间!");
        }
        if(salaryTime.split("-").length==3){
            salaryTime=salaryTime.split("-")[0]+"-"+salaryTime.split("-")[1];
        }
        List<SSalary> sSalaryList=new ArrayList<SSalary>();

        //获取excel的行属性名称
        List<String> itemKeyList = (List<String>) salaryArray.get(0);
        List<Map<String,Object>> salMapList=new ArrayList<Map<String,Object>>();
        for(int i=1;i<salaryArray.size();i++){
             //获取各项值
              List<String> itemValueList= (List<String>) salaryArray.get(i);
              Map<String,Object> salMap=new HashMap<String,Object>();
              for( int k=0;k<itemValueList.size();k++){
                  salMap.put(itemKeyList.get(k).toString(),itemValueList.get(k));
              }
              salMapList.add(salMap);
        }
        for( int i=0;i<salMapList.size();i++){
            SSalary sl=new SSalary();
            Map<String,Object> js=salMapList.get(i);
            String sOrder= (String) js.get("序号");
            String staffName = (String) js.get("姓名");
            String companyName= (String) js.get("所属公司");
            String postName = (String) js.get("岗位名称");
            String projectGroup = (String) js.get("项目组别");
            String entryTime = (String) js.get("入职时间");
            String basicSalary=ConstentUtil.isEmpty(js.get("基本工资")) ? "0" : (String) js.get("基本工资");
            String attendanceAssessment= ConstentUtil.isEmpty(js.get("考勤考评")) ? "0" : (String) js.get("考勤考评") ;
            String floatingPerformance=ConstentUtil.isEmpty(js.get("浮动绩效")) ? "0" : (String)js.get("浮动绩效") ;
            String reimburse=ConstentUtil.isEmpty(js.get("报销")) ? "0" : (String) js.get("报销");
            String descrpition= (String) js.get("备注");
            String initialRank= (String) js.get("初定职级");
            String primary= (String) js.get("初级");
            String intermediate= (String) js.get("中级");
            String advanced= (String) js.get("高级");
            String payAssessment=ConstentUtil.isEmpty(js.get("评定薪资")) ? "0": (String) js.get("评定薪资");

            String yingChuQin=ConstentUtil.isEmpty(js.get("当月考勤天数")) ? "0" : (String) js.get("当月考勤天数");
            String shiJiChuQin=ConstentUtil.isEmpty(js.get("正常出勤天数"))? "0" : (String) js.get("正常出勤天数");

            if(ConstentUtil.isEmpty(yingChuQin)){
                return ResponseResult.fail("请添加当月考勤天数");
            }
            if(ConstentUtil.isEmpty(shiJiChuQin)){
                return ResponseResult.fail("请添加正常出勤天数");
            }
            if(ConstentUtil.isEmpty(basicSalary)){
                return ResponseResult.fail("请添加基本工资");
            }
            //算当月工资 : 正常出勤天数/当月考勤天数 * 基本工资
            double monthlySalary = ConstentUtil.strToDouble(shiJiChuQin) /
                    ConstentUtil.strToDouble(yingChuQin)
                    * ConstentUtil.strToDouble(basicSalary);

            //计算1.5倍外包协议价 ：  当月工资*1.5
            double contractPrice15times= monthlySalary * 1.5;

            //计算应发外包费： 1.5倍外包协议价+考勤考评+浮动绩效+报销
            double outsourcingFeesPayable=contractPrice15times+
                    ConstentUtil.strToDouble(attendanceAssessment)
                    +ConstentUtil.strToDouble(floatingPerformance)
                    +ConstentUtil.strToDouble(reimburse);

            //计算代扣社保 （其中社保基数默认为最低3510）:=社保基数*0.08+社保基数*0.02+社保基数*0.003
            double daiKouSheBao=ReturnValueConstants.SHE_BAO_JI_SHU*0.08
                    + ReturnValueConstants.SHE_BAO_JI_SHU*0.02
                    +ReturnValueConstants.SHE_BAO_JI_SHU*0.003;
            sl.setDaiKouSheBao(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(daiKouSheBao)));

            //计算代扣公积金 :公积金基数*0.05
            double daiKouGongJiJin =ReturnValueConstants.GONG_JI_JIN_JI_SHU*ReturnValueConstants.GONG_JI_JIN_JIAO_FEI_BI_LI;

            /**************************************************后续修改代扣个税****************************************/
//            double daiKouGeShui=95.8;

            double shiFaGongZi=monthlySalary-daiKouGongJiJin-daiKouSheBao;//-daiKouGeShui;

            sl.setDaiKouKongJiJin(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(daiKouGongJiJin)));
            sl.setShiFaGongZi(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(shiFaGongZi)));
            sl.setCompanyCode(companyCode);
            sl.setYingChuQin(yingChuQin);
            sl.setShiJiChuQin(shiJiChuQin);
            sl.setYingFaSalary(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(monthlySalary)));
            sl.setPayAssessment(payAssessment);
            sl.setAdvanced(advanced);
            sl.setIntermediate(intermediate);
            sl.setPrimary(primary);
            sl.setInitialRank(initialRank);
            sl.setDescrpition(descrpition);
            sl.setOutsourcingFeesPayable(ConstentUtil.formatDouble1(outsourcingFeesPayable)+"");
            sl.setReimburse(reimburse);
            sl.setFloatingPerformance(floatingPerformance);
            sl.setAttendanceAssessment(attendanceAssessment);
            sl.setContractPrice15times(ConstentUtil.formatDouble1(contractPrice15times)+"");
            sl.setMonthlySalary(ConstentUtil.formatDouble1(monthlySalary)+"");
            sl.setSalaryCreateTime(salaryTime);
            sl.setBasicSalary(basicSalary);
            sl.setTotalSalary(basicSalary);
            sl.setEntryTime(entryTime);
            sl.setProjectGroup(projectGroup);
            sl.setPostName(postName);
            sl.setCompanyName(companyName);
            sl.setStaffName(staffName);
            sl.setsOrder(sOrder);

            sl.setTotalSalary(ConstentUtil.formatDouble1(monthlySalary)+"");

            sSalaryList.add(sl);
        }
        try {
                 int num=salaryService.insertSalaryList(sSalaryList);
                 logger.info("添加薪资信息列表成功!添加条数:{}",num);
                 return ResponseResult.success(ReturnValueConstants.ADD_SUCCESS,num);
             } catch (Exception e) {
                 logger.info("添加薪资信息列表异常!");
                 e.printStackTrace();
                 return ResponseResult.fail(ReturnValueConstants.ADD_FAILURE);
             }
    }

    /**
     * 管理员查询薪资列表
     * @param jsonObject
     * @return
     */
    @ApiOperation(value = "薪资信息列表查询接口", notes = "薪资信息列表查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "staffName", value = "员工姓名")
    })
    @PostMapping(value = "selectSalaryInfo")
    public ResponseResult selectSalaryInfo(@RequestBody(required = false) JSONObject jsonObject,HttpServletRequest request){

        String token = request.getHeader("token");
        System.out.println("token===="+token);
        Map<String,Object> userMap=  (Map<String,Object>)redisService.get(token);
        String  companyCode = (String) userMap.get("companyCode");
//        String  companyCode = "SDHH";

        String staffName=null;
       if(!ConstentUtil.isEmpty(jsonObject)){
           staffName=jsonObject.getString("staffName");
       }
       String selTime=null;
       if(!ConstentUtil.isEmpty(jsonObject)){
           selTime=jsonObject.getString("salaryTime");
       }else{
           selTime=DateUtil.getPreviousMoth();
       }
       if(!ConstentUtil.isEmpty(selTime) && selTime.split("-").length ==3){
           selTime=selTime.split("-")[0]+"-"+selTime.split("-")[1];
       }
        SSalary sSalary=new SSalary();
       sSalary.setSalaryCreateTime(selTime);
        sSalary.setCompanyCode(companyCode);
        //如果有员工名称，则根据员工姓名查询
        if(!ConstentUtil.isEmpty(staffName)){
            sSalary.setStaffName(staffName);
        }
        try {
                 List<SSalary> sSalaryList= salaryService.selectSalaryInfo(sSalary);
                 String showTime=DateUtil.getPreviousMoth();
                 if(!ConstentUtil.isEmpty(sSalaryList)){
                     showTime=sSalaryList.get(0).getSalaryCreateTime();
                 }
                 Map<String,Object> map=new HashMap<String,Object>();
                 map.put("salaryList",sSalaryList);
                 map.put("time",showTime.split("-")[0]+"年"+showTime.split("-")[1]);
                 logger.info("查询公司薪资信息列表成功!列表为:{}",sSalaryList);
                 return ResponseResult.success(ReturnValueConstants.QUERY_SUCCESS,map);
             } catch (Exception e) {
                 logger.error("查询公司薪资信息列表异常!");
                 e.printStackTrace();
                 return ResponseResult.fail(ReturnValueConstants.QUERY_FAILURE);
             }
    }

    /**
     * 查询个人薪资信息
     * @return
     */
    @ApiOperation(value = "查询个人薪资信息接口", notes = "查询个人薪资信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "salaryTime", value = "月份")
    })
    @PostMapping(value = "selectPrimarySalaryInfo")
    public ResponseResult selectPrimarySalaryInfo(@RequestBody(required = false) JSONObject jsonObject,HttpServletRequest request){
        String token = request.getHeader("token");
        System.out.println("token===="+token);
        Map<String,Object> userMap=  (Map<String,Object>)redisService.get(token);
        String  companyCode = (String) userMap.get("companyCode");
        String userName=(String) userMap.get("userName");
//        String  companyCode = "SDHH";
//        String userName="CESHI";
        String selMonth=null;
        if(!ConstentUtil.isEmpty(jsonObject)){
            selMonth=jsonObject.getString("salaryTime");
        }else{
            selMonth=DateUtil.getPreviousMoth();
        }
        selMonth=DateUtil.formatDate(ReturnValueConstants.DATE_FORMAT_YYYY_MM,selMonth);
        SSalary sSalary=new SSalary();
        sSalary.setCompanyCode(companyCode);
        sSalary.setStaffName(userName);
        sSalary.setSalaryCreateTime(selMonth);
        try {
            String showTime=DateUtil.getPreviousMoth();
            List<SSalary> salaryList = salaryService.selectPrimarySalaryInfo(sSalary);
            if(!ConstentUtil.isEmpty(salaryList)){
                showTime=salaryList.get(0).getSalaryCreateTime();
            }
            showTime=showTime.split("-")[0]+"-"+showTime.split("-")[1];
            Map<String,Object> map=new HashMap<String,Object>();
            map.put("salaryList",salaryList);
            map.put("time",showTime);
            logger.info("查询个人薪资信息成功:{}", salaryList);
            return ResponseResult.success(ReturnValueConstants.QUERY_SUCCESS, map);
        } catch (Exception e) {
            logger.error("查询个人薪资信息异常!");
            e.printStackTrace();
            return ResponseResult.fail(ReturnValueConstants.QUERY_FAILURE);
        }
    }

    /**
     * 根据id查询薪资信息
     * @param jsonObject
     * @return
     */
    @ApiOperation(value = "根据id查询薪资信息", notes = "根据id查询薪资信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "薪资id",required = true)
    })
    @PostMapping(value = "findSalaryInfoById")
    public ResponseResult findSalaryInfoById(@RequestBody JSONObject jsonObject){
        Integer id=jsonObject.getInteger("id");
        if(ConstentUtil.isEmpty(id)){
            return ResponseResult.fail("请选择要查询的薪资信息");
        }
        try {
                 SSalary sSalary=salaryService.findSalaryInfoById(id);
                 logger.info("根据id查询薪资信息成功，{}",sSalary);
                 return ResponseResult.success(ReturnValueConstants.QUERY_SUCCESS,sSalary);
             } catch (Exception e) {
                 logger.error("根据id查询薪资信息异常");
                 e.printStackTrace();
                 return ResponseResult.fail(ReturnValueConstants.QUERY_FAILURE);
             }
    }

    /**
     * 管理员修改薪资信息
     * @param  jsonObject
     * @return
     */
    @ApiOperation(value = "管理员修改薪资信息接口", notes = "管理员修改薪资信息")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "staffName", value = "员工姓名")
    })
    @PostMapping(value = "updateSalaryInfo")
    public ResponseResult updateSalaryInfo(@RequestBody JSONObject jsonObject) throws Exception {
//        SSalary ss1=new SSalary();
        SSalary sSalary= (SSalary) ConstentUtil.json2Object(jsonObject,SSalary.class);
        String yingChuQin=sSalary.getYingChuQin();
        String shiJiChuQin=sSalary.getShiJiChuQin();
        String basicSalary=sSalary.getBasicSalary();
        double monthlySalary =ConstentUtil.strToDouble(ConstentUtil.isEmpty(sSalary.getMonthlySalary()) ? "0" :sSalary.getMonthlySalary());
        double jiaBanBuTie =ConstentUtil.strToDouble(ConstentUtil.isEmpty(sSalary.getJiaBanBuTie()) ? "0" : sSalary.getJiaBanBuTie());
        double chuChaiBuTie =ConstentUtil.strToDouble(ConstentUtil.isEmpty(sSalary.getChuChaiBuTie()) ? "0" : sSalary.getChuChaiBuTie());
        double jiXiaoJiangLi =ConstentUtil.strToDouble(ConstentUtil.isEmpty(sSalary.getJiXiaoJiangLi())? "0" : sSalary.getJiXiaoJiangLi());
        double kaoQinKouKuan =ConstentUtil.strToDouble(ConstentUtil.isEmpty(sSalary.getKaoQinKouKuan()) ? "0" :sSalary.getKaoQinKouKuan());
        double qiTaKouKuan =ConstentUtil.strToDouble(ConstentUtil.isEmpty(sSalary.getQiTaKouKuan()) ? "0" : sSalary.getQiTaKouKuan());
        double zhuanXiangFuJia =ConstentUtil.strToDouble(ConstentUtil.isEmpty(sSalary.getZhuanXiangFuJiaKouChu()) ? "0" : sSalary.getZhuanXiangFuJiaKouChu());
        //如果修改正常出勤天数或者考勤天数，则修改当月工资
        if(!ConstentUtil.isEmpty(yingChuQin) && !ConstentUtil.isEmpty(shiJiChuQin)){
            //重新计算当月工资 : 正常出勤天数/当月考勤天数 * 基本工资
             monthlySalary = ConstentUtil.strToDouble(shiJiChuQin) /
                   ConstentUtil.strToDouble(yingChuQin)
                    * ConstentUtil.strToDouble(basicSalary);
            sSalary.setMonthlySalary(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(monthlySalary)));
        }

        //计算加班补助 :加班补贴=基本工资/20.95/8*（工作日加班时数*1.5+周末*2+法假*3）
        String jiaBanGongZuoRi=sSalary.getJiaBanGongZuoRi();
        String jiaBanZhouMo=sSalary.getJiaBanZhouMo();
        String jiaBanFaJia=sSalary.getJiaBanFaJia();
        if(!ConstentUtil.isEmpty(jiaBanZhouMo) || !ConstentUtil.isEmpty(jiaBanGongZuoRi) ||
                !ConstentUtil.isEmpty(jiaBanFaJia)){

               jiaBanBuTie=ConstentUtil.strToDouble(basicSalary)/
                    ReturnValueConstants.JIA_BAN_JI_SHU/8*
                    (ConstentUtil.strToDouble(jiaBanGongZuoRi)*1.5
                    +ConstentUtil.strToDouble(jiaBanZhouMo)*2
                    +ConstentUtil.strToDouble(jiaBanFaJia)*3
                    );
            sSalary.setJiaBanBuTie(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(jiaBanBuTie)));
        }

        //计算应发工资:本月工资+加班补助+出差补助+绩效奖励-考勤扣款-其他扣款
        double yingFaGongZi=monthlySalary+jiaBanBuTie+chuChaiBuTie+jiXiaoJiangLi-kaoQinKouKuan-qiTaKouKuan;
        sSalary.setYingFaSalary(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(yingFaGongZi)));

        //计算代扣社保 （其中社保基数默认为最低3510）:=社保基数*0.08+社保基数*0.02+社保基数*0.003
        double daiKouSheBao=ReturnValueConstants.SHE_BAO_JI_SHU*0.08
                + ReturnValueConstants.SHE_BAO_JI_SHU*0.02
                +ReturnValueConstants.SHE_BAO_JI_SHU*0.003;
        sSalary.setDaiKouSheBao(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(daiKouSheBao)));

        //计算代扣公积金 :公积金基数*0.05
        double daiKouGongJiJin =ReturnValueConstants.GONG_JI_JIN_JI_SHU*ReturnValueConstants.GONG_JI_JIN_JIAO_FEI_BI_LI;
        sSalary.setDaiKouKongJiJin(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(daiKouGongJiJin)));

        /**************************************************后续修改代扣个税****************************************/

        //计算当年之前累计工资信息，便于计算个税信息
        SSalary ss=salaryService.findSalaryInfoById(sSalary.getId());
        Map<String,Object> selectMap=new HashMap<String,Object>();
        selectMap.put("staffName",ss.getStaffName());
        String enTime=ss.getSalaryCreateTime();
        int dangNian=Integer.valueOf(enTime.split("-")[0]);
        selectMap.put("beginTime", DateUtil.dateToStr(DateUtil.getYearFirst(dangNian)));
        selectMap.put("endTime", enTime);
        selectMap.put("companyCode",ss.getCompanyCode());
        List<SSalary> sSalaryWithOutList=salaryService.getLeiJiSalaryInfoList(selectMap);
        sSalaryWithOutList.remove(0);

        //获取之前累计信息
        //累计应缴税额
        Double leiJiYiJiaoShuiE= 0.00;
        //累计专项附加
        Double leiJiZhuanXiangFuJia= 0.00;
        //累计应纳税额
        Double leiJiYingNaShuiE= 0.00;
        //累计五险一金
        Double leiJiWuXianYiJin= 0.00;
        //累计收入
        Double leiJiShouRu= 0.00;
        //费用扣除标准
        Double feiYongKouChuBiaoZhun= 0.00;
        //预交应纳税所得
        Double yuJiaoYingNaShuiSuoDe=0.00;
        if(!ConstentUtil.isEmpty(sSalaryWithOutList)){
                SSalary sSalary1=sSalaryWithOutList.get(0);
                //获取之前的累计已缴税额
                leiJiYiJiaoShuiE=ConstentUtil.strToDouble(sSalary1.getLeiJiYiJiaoShuiE());
                //获取之前累计专项附加
                leiJiZhuanXiangFuJia=ConstentUtil.strToDouble(sSalary1.getLeiJiZhuanXiangFuJia());
                //获取累计应纳税额
                leiJiYingNaShuiE=ConstentUtil.strToDouble(sSalary1.getLeiJiYingNaShuiE());
                //累计五险一金
                leiJiWuXianYiJin =ConstentUtil.strToDouble(sSalary1.getLeiJiWuXianYiJin());
                //累计收入
                leiJiShouRu=ConstentUtil.strToDouble(sSalary1.getLeiJiShouRu());
                //费用扣除标准
                feiYongKouChuBiaoZhun=ConstentUtil.strToDouble(sSalary1.getFeiYongKouChuBiaoZhun());

        }
        leiJiShouRu+=yingFaGongZi;
        leiJiZhuanXiangFuJia+=zhuanXiangFuJia;
        leiJiWuXianYiJin+=daiKouSheBao+daiKouGongJiJin;
        feiYongKouChuBiaoZhun+=ReturnValueConstants.GE_SHUI_QI_ZHENG_DIAN;
        //计算个人所得税

        //计算预交应纳税所得=累计收入-累计费用扣除标准-累计五险一金-累计专项附加，该系统没有添加其他扣除
        yuJiaoYingNaShuiSuoDe=leiJiShouRu-feiYongKouChuBiaoZhun-leiJiWuXianYiJin-leiJiZhuanXiangFuJia;
        Map<String,Object> llMap=ConstentUtil.getKouChuShuiLuAndSuSuanKouChuShu(yuJiaoYingNaShuiSuoDe);
        //计算出累计应纳税额
        Double leiJiYingNaShui= ConstentUtil.getTaxNum(yuJiaoYingNaShuiSuoDe,llMap);
        //计算代扣个税=应纳税额-累计已交税额
        double daiKouGeShui=leiJiYingNaShui-leiJiYingNaShuiE;
//        leiJiYingNaShuiE+=daiKouGeShui;
        double shiFaGongZi=yingFaGongZi-daiKouGongJiJin-daiKouSheBao-daiKouGeShui;
        sSalary.setZhuanXiangFuJiaKouChu(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(zhuanXiangFuJia)));
        sSalary.setShiFaGongZi(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(shiFaGongZi)));
        sSalary.setLeiJiShouRu(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(leiJiShouRu)));
        sSalary.setLeiJiYingNaShuiE(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(leiJiYingNaShui)));
        sSalary.setLeiJiZhuanXiangFuJia(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(leiJiZhuanXiangFuJia)));
        sSalary.setLeiJiWuXianYiJin(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(leiJiWuXianYiJin)));
        sSalary.setFeiYongKouChuBiaoZhun(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(feiYongKouChuBiaoZhun)));
        sSalary.setDaiKouGeShui(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(daiKouGeShui)));
        sSalary.setLeiJiYiJiaoShuiE(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(leiJiYingNaShuiE)));
        sSalary.setDaiKouKongJiJin(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(daiKouGongJiJin)));
        sSalary.setYuJiaoYingNaShuiSuoDe(ConstentUtil.doubleToStr(ConstentUtil.formatDouble1(yuJiaoYingNaShuiSuoDe)));
        try {
            int num = salaryService.updateSalaryInfoById(sSalary);
            logger.info("修改薪资信息成功:{}", sSalary);
            return ResponseResult.success(ReturnValueConstants.UPDATE_SUCCESS, sSalary);
        } catch (Exception e) {
            logger.error("查询个人薪资信息异常!");
            e.printStackTrace();
            return ResponseResult.fail(ReturnValueConstants.UPDATE_SUCCESS);
        }
    }
}
